##################################
## compiler configuration
CUTIL_HOME       = /home/yuwei/NVIDIA_GPU_Computing_SDK
CUDA_HOME       = /usr/local/cuda
BOOST_HOME      = /usr/include
NVCCFLAGS       = -O3 -arch=sm_20




#################################

CC              = g++
NVCC            = nvcc
INCLUDE         = -I./cpp -I../common -I./ -I$(CUDA_HOME)/include -I$(CUTIL_HOME)/C/common/inc -I$(BOOST_HOME) -I./kernel -I../container
LIB             = -L/usr/local/lib -L$(CUDA_HOME)/lib64 -L$(CUTIL_HOME)/C/lib -lcutil_x86_64 -lcuda -lcudart -L../container -lcontainer
CFLAGS          = -g -O3 -fomit-frame-pointer -ffast-math -funroll-loops -mmmx -msse -msse2 -msse3 -fmessage-length=0

AR = ar
AFLAGS = -r

###################################
# the generated targets
# the library libgsnp.a
LGSNP_TARGET = libgsnp.a
# the library libcmat.a
LCMAT_TARGET = libcmat.a
LCMAT_OBJ = libcmat.o chromosome.o
# the executable file gsnp
GSNP_OBJ        = gsnp_main.o call_genotype.o chromosome.o matrix.o normal_dis.o prior.o rank_sum.o gsnp_kernel.o compress_kernel.o main.o
# the executable file decompression
DECOMP_OBJ	= decompression.o compress_kernel.o
# the executable file count_matrix
MATRIX_OBJ	= count_matrix.o chromosome.o





$(LGSNP_TARGET): $(GSNP_OBJ)
	$(AR) $(AFLAGS) $(LGSNP_TARGET) $(GSNP_OBJ)
$(LCMAT_TARGET): $(LCMAT_OBJ)
	$(AR) $(AFLAGS) $(LCMAT_TARGET) $(LCMAT_OBJ)
gsnp: $(GSNP_OBJ)
	$(CC) -o gsnp $(GSNP_OBJ) $(CFLAGS) $(INCLUDE) $(LIB)
decompression: $(DECOMP_OBJ)
	$(CC) -o decompression $(DECOMP_OBJ) $(CFLAGS) $(INCLUDE) $(LIB)
count_matrix: $(MATRIX_OBJ)
	$(CC) -o count_matrix $(MATRIX_OBJ) $(CFLAGS) $(INCLUDE) $(LIB)


libcmat.o: ./cpp/libcmat.cpp
	$(CC) -c ./cpp/libcmat.cpp $(CFLAGS) $(INCLUDE)
gsnp_main.o: ./cpp/gsnp_main.cpp
	$(CC) -c ./cpp/gsnp_main.cpp $(CFLAGS) $(INCLUDE)
count_matrix.o: ./cpp/count_matrix.cpp
	$(CC) -c ./cpp/count_matrix.cpp $(CFLAGS) $(INCLUDE)
call_genotype.o: ./cpp/call_genotype.cc
	$(CC) -c ./cpp/call_genotype.cc $(CFLAGS) $(INCLUDE)
chromosome.o: ./cpp/chromosome.cc
	$(CC) -c ./cpp/chromosome.cc $(CFLAGS) $(INCLUDE)
matrix.o: ./cpp/matrix.cc
	$(CC) -c ./cpp/matrix.cc $(CFLAGS) $(INCLUDE)
normal_dis.o: ./cpp/normal_dis.cc
	$(CC) -c ./cpp/normal_dis.cc $(CFLAGS) $(INCLUDE)
prior.o: ./cpp/prior.cc
	$(CC) -c ./cpp/prior.cc $(CFLAGS) $(INCLUDE)
rank_sum.o: ./cpp/rank_sum.cc
	$(CC) -c ./cpp/rank_sum.cc $(CFLAGS) $(INCLUDE)
gsnp_kernel.o: ./kernel/gsnp_kernel.cu
	$(NVCC) -c ./kernel/gsnp_kernel.cu $(NVCCFLAGS) $(INCLUDE)
compress_kernel.o: ./kernel/compress_kernel.cu
	$(NVCC) -c ./kernel/compress_kernel.cu $(NVCCFLAGS) $(INCLUDE)
main.o: ./cpp/main.cc
	$(CC) -c ./cpp/main.cc $(CFLAGS) $(INCLUDE)
decompression.o: ./cpp/decompression.cpp
	$(CC) -c ./cpp/decompression.cpp $(CFLAGS) $(INCLUDE)
all: gsnp decompression libgsnp.a libcmat.a count_matrix

clean:
	rm *.o libgsnp.a libcmat.a decompression gsnp count_matrix
